package com.taotao.controller;

import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.service.ContentCategoryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/content/category")
@Controller
public class ContentCategoryController {
	@Autowired
	private ContentCategoryService contentCategoryService;

	@RequestMapping("/list")
	@ResponseBody
	public List<EasyUITreeNode> getContentCategoryList(
			@RequestParam(value = "id", defaultValue = "0") long parentId) {
		List<EasyUITreeNode> resultList = contentCategoryService
				.getContentCategoryList(parentId);

		return resultList;
	}

	@RequestMapping("/create")
	@ResponseBody
	public TaotaoResult insertCategory(long parentId, String name) {
		TaotaoResult result = contentCategoryService.insertCategory(parentId,
				name);

		return result;
	}

	@RequestMapping("/update")
	@ResponseBody
	public TaotaoResult updateCategory(long id, String name) {
		TaotaoResult result = contentCategoryService.updateCategory(id, name);
		return result;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public TaotaoResult deleteCategory(@RequestParam("id") long id) {
		TaotaoResult result = contentCategoryService.deleteCategory(id);
		return result;
	}
}
